package com.zqq.user.presenter

import com.zqq.baselibrary.ext.excute
import com.zqq.baselibrary.http.rx.BaseSubscriber
import com.zqq.baselibrary.presenter.BasePresenter
import com.zqq.user.presenter.view.LoginView
import com.zqq.user.service.UserService
import com.zqq.user.service.bean.UserInfo
import javax.inject.Inject
import javax.inject.Named

/**
 * 登录界面 Presenter
 * wc
 * @author zqq on 2018/7/27
 */
class LoginPresenter @Inject constructor() : BasePresenter<LoginView>() {

    @Inject
    @field:[Named("service")]
    lateinit var userService: UserService

    /**
     * 登录
     */
    fun login(mobile: String, pwd: String, pushId: String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        userService.login(mobile, pwd, pushId)
                .excute(object : BaseSubscriber<UserInfo>(mView) {
                    override fun onNext(t: UserInfo) {
                        mView.onLoginResult(t)
                    }

                    override fun onError(e: Throwable) {
                        super.onError(e)
                        val icon = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1558782436686&di=1b927a105b649d4299de71731c321b67&imgtype=0&src=http%3A%2F%2Fimg2.ph.126.net%2FJ3JHQOYyAV2xBU84epsR9w%3D%3D%2F4905545894214113834.jpg"

                        val t = UserInfo("1", icon, "zxx", "0", "13122234225", "xx")
                        mView.onLoginResult(t)
                    }
                }, lifecycleProvider)

    }


}